package com.tim.framework.util.properties;

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;

/**
 * 资源文件操作.
 * 
 * @author Tim.
 */
public class JDKPropertiesProc extends AbsPropertiesProc {
	private static Logger log = Logger.getLogger(JDKPropertiesProc.class);

	/**
	 * 获取属性值.
	 */
	public String getValue(String key) {
		Map<String, Properties> propertiesCache = getPropertiesCache();
		Set<String> keySet = propertiesCache.keySet();
		String value = null;
		for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
			String itemKey = (String) iterator.next();
			value = propertiesCache.get(itemKey).getProperty(key);
			if (value != null)
				break;
		}
		return value;
	}

	/**
	 * 添加资源文件内容.
	 * 
	 * @param key
	 *            资源Key.
	 * @param value
	 *            资源Value.
	 */
	public boolean addValue(String key, String value) {
		Properties props = new Properties();
		// 设置属性值
		props.setProperty(key, value);
		// 写入文件
		// props.store(out, comments);
		return true;
	}
}
